import '../../../app_files.dart';

class MeterFactoryModel {
  String controlCode;
  String meterFactory;
  String meterType;

  ///气表种类
  List<Map> meterSpecs = [];
  List<Map> meterUnitTypes = [];

  int selectMeterSpec;
  String selectUnitType;
}

class MeterInfoModel {
  MeterInfoModel();

  String meterId;

  ///左 右
  String meterBiaoxiang;

  /// 1 户内 2 户外
  int meterInstallType = 1;

  ///表底
  String meterBaseVolume = '';

  /// 1、IC卡表 2、NB-IOT物联网表 3、机表;
  String meterType;

  ///备注
  String meterMemo = '';

  ///气表编号
  String meterNo = '';

  /// 1 计费  2 计量
  int meterFeeMode = 1;

  ///是否加封
  int isClosed = 0;
  String meterFengNumber = '';

  ///表厂  "金额小表,金额大表(6-25方),金额大表(流量计)|1=金额计费|99999|10008919|2
  String meterFactory;

  ///母表类型
  String meterUnitType;

  ///气表类型
  String meterSpecs;
  String meterCtrlCode;

  // ///身份证号
  // String userIdNo;

  setJsonInfo(json) {
    meterNo = CommonUtils.checkNullToString(json['MeterNo']);
    meterFactory = CommonUtils.checkNullToString(json['MeterFactory']);
    meterBiaoxiang = CommonUtils.checkNullToString(json['MeterBiaoxiang']);
    meterBaseVolume = CommonUtils.checkNullToString(json['MeterBaseVolume']);
    isClosed =
        int.tryParse(CommonUtils.checkNullToString(json['MeterIsJiaFeng'])) ??
            0;
    meterFengNumber = CommonUtils.checkNullToString(json['MeterFengNumber']);
  }

  Map toOrderMap() {
    return {
      'MeterNo': meterNo,
      'MeterFactory': meterFactory,
      'MeterBiaoxiang': meterBiaoxiang,
      'MeterBaseVolume': meterBaseVolume,
      'MeterIsJiaFeng': isClosed,
      'MeterFengNumber': meterFengNumber,
    };
  }
}

class EngineerMaterList {
  String itemId;
  String materName;
  double price;
  String unit;
  bool defaultMater;

  String get desc => '$materName  $price/$unit';
  int number = 1;

  EngineerMaterList({
    this.itemId,
    this.materName,
    this.price,
    this.unit,
    this.number = 1,
    this.defaultMater = true,
  });

  static fromJson(json) {
    return EngineerMaterList(
      itemId: CommonUtils.checkNullToString(json['materialId']),
      materName: CommonUtils.checkNullToString(json['materialName']),
      price: double.tryParse(
              CommonUtils.checkNullToString(json['materialPrice'])) ??
          0.0,
      unit: CommonUtils.checkNullToString(json['materialUnit']),
      defaultMater: CommonUtils.checkNullToString(json['isDefault']) == '1',
    );
  }

  static fromDetail(json) {
    return EngineerMaterList(
      itemId: CommonUtils.checkNullToString(json['bmrelMaterialId']),
      materName: CommonUtils.checkNullToString(json['bmrelName']),
      price:
          double.tryParse(CommonUtils.checkNullToString(json['bmrelPrice'])) ??
              0.0,
      number: (double.tryParse(
                  CommonUtils.checkNullToString(json['bmrelNumber'])) ??
              0.0)
          .toInt(),
    );
  }

  toMap() {
    Map info = {};
    info['bmrelMaterialId'] = itemId;
    info['bmrelName'] = materName;
    info['bmrelPrice'] = price;
    info['bmrelNumber'] = number;
    return info;
  }

  @override
  bool operator ==(Object other) {
    return other is EngineerMaterList && other.itemId == itemId;
  }

  @override
  int get hashCode => itemId.hashCode;
}

class GoodsNumberWidget extends StatelessWidget {
  final double size;
  final Function() onTapMin;
  final Function() onTapAdd;
  final Function() onTapText;

  const GoodsNumberWidget({
    this.size = 33,
    this.goodsNumber,
    this.minGoodsNumber = 0,
    this.onTapMin,
    this.onTapAdd,
    this.onTapText,
  });

  final int goodsNumber;
  final int minGoodsNumber;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        MyInkWellWidget(
          child: Container(
            width: size,
            height: size - 1,
            margin: const EdgeInsets.only(left: 12, top: 8, bottom: 8),
            decoration: BoxDecoration(
              border: Border.all(color: const Color(0xffcccccc), width: 0.5),
              borderRadius: const BorderRadius.only(
                  topLeft: Radius.circular(4), bottomLeft: Radius.circular(4)),
            ),
            child: Center(
              child: Text(
                '-',
                style: TextThemeConfig.Font12WithColor22.merge(TextStyle(
                    height: 1,
                    fontSize: 15,
                    color: minGoodsNumber == goodsNumber
                        ? const Color(0xff999999)
                        : const Color(0xff333333))),
              ),
            ),
          ),
          onTap: () {
            if (goodsNumber != minGoodsNumber) {
              onTapMin();
            }
          },
        ),
        MyInkWellWidget(
            child: Container(
              width: size,
              height: size - 1,
              decoration: const BoxDecoration(
                border: Border(
                  top: BorderSide(color: Color(0xffcccccc), width: 0.5),
                  bottom: BorderSide(color: Color(0xffcccccc), width: 0.5),
                ),
              ),
              child: Center(
                child: Text(
                  '$goodsNumber',
                  style:
                      TextThemeConfig.Font12WithColor22.merge(const TextStyle(
                    height: 1,
                  )),
                ),
              ),
            ),
            onTap: () {
              if (onTapText != null) {
                onTapText();
              }
            }),
        MyInkWellWidget(
          child: Container(
            width: size,
            height: size - 1,
            margin: const EdgeInsets.only(right: 12, top: 8, bottom: 8),
            decoration: BoxDecoration(
              border: Border.all(color: const Color(0xffcccccc), width: 0.5),
              borderRadius: const BorderRadius.only(
                  topRight: Radius.circular(4),
                  bottomRight: Radius.circular(4)),
            ),
            child: Center(
              child: Text(
                '+',
                style: TextThemeConfig.Font12WithColor22.merge(const TextStyle(
                  height: 1,
                  fontSize: 15,
                )),
              ),
            ),
          ),
          onTap: () => onTapAdd(),
        ),
      ],
    );
  }
}
